<template>
<div class="fixed-center background-popup">
  <div class="box p20 font-white-color">
    <div v-for="(item, index) in allData" class="item">
      <div class="p10">{{allData[index].key}}</div>
      <input type="text" :value="allData[index].value" @input="onChangeKey($event, index)">
    </div>
  </div>
  <div class="font-center">
    <van-button @click="changeKeys" color="#3b5e75db" type="primary">确认</van-button>
  </div>
</div>
</template>

<script>
import { Button } from "vant";
export default{
  components: {
    [Button.name]: Button,
  },
  props: {
    keys: {
      type: Array,
      default: []
    },
    values: {
      type: Array,
      default: []
    }
  },
  data(){
    return {
      allData: [{
        key: '',
        value: ''
      }],
    }
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      let data = this.keys.length > this.values.length ? this.keys : this.values;
      this.allData = data.map((v, i) => {
        return {
          key: this.keys[i] ?? '',
          value: this.values[i] ?? ''
        }
      });
    },
    onChangeKey(e, i) {
      this.allData[i].value = '';
      this.allData[i].value = e.data;
    },
    changeKeys(){
      this.$emit('on-change', this.allData);
    }
  }
}
</script>

<style scoped>
input{
  width: 100%;
  height: 26px;
  display: inline-block;
  border: unset;
  color: rgb(66, 76, 80);
  text-align: center;
}
.box {
  width: 215px;
  height: 200px;
  margin: 0 auto;
  overflow-y: scroll;
  display: flex;
  flex-wrap: wrap;
}
/* 设置滚动条 */
::-webkit-scrollbar{
  width: 4px;
  background-color: rgb(74, 75, 77);
}
::-webkit-scrollbar-thumb {
  border-radius:10px;
  background:rgb(199, 221, 230);
}
/* 设置滚动条 end */
.box .item {
  width: 60px;
  height: 80px;
  margin: 10px 5px;
  box-sizing: border-box;
  border: 1px solid rgb(153, 153, 153);
}
</style>